package cn.stimd.spring.aop.support.annotation;

import cn.stimd.spring.aop.ClassFilter;
import org.springframework.core.annotation.AnnotationUtils;

import java.lang.annotation.Annotation;

/**
 * Created by Stimd
 * 项目地址：https://gitee.com/stimd/spring-wheel
 * 公众号：Java编程探微
 */
public class AnnotationClassFilter implements ClassFilter {
    private final Class<? extends Annotation> annotationType;

    public AnnotationClassFilter(Class<? extends Annotation> annotationType) {
        this.annotationType = annotationType;
    }

    @Override
    public boolean matches(Class<?> clazz) {
        //当前类及其父类是否存在指定注解
        return AnnotationUtils.findAnnotation(clazz, this.annotationType) != null;
    }
}
